<template>
    <div class="download_bt" @click="on_download">
        <div class="left">
            <slot name="left"></slot>
        </div>
        <div class="right">
            下载
        </div>
    </div>
</template>
<script>
const ipc = require('electron').ipcMain;
const dialog = require('electron').dialog;
export default { //下载按钮组件
    name:'Download_bt',
    data(){
        return{

        };
    },
    created(){
        console.log(ipc);
        console.log(dialog);
    },
    methods:{
        on_download(){ //文件下载
            if(this.$store.state.selection_files.length){
                this.$store.commit('set_loading',{
                    state:true,
                });
                let fileNames=this.$store.state.selection_files.map(item=>{
                    return item.fileName || item.hadoopFileName;
                }) || [];
                this.$axios.json_post('file/download',{
                    fileName:fileNames.join(","),
                    downName:"",
                }).then((data)=>{
                    this.$message(data);
                    // let blob = new Blob([response.data], {
                    // type: 'application/vnd.ms-excel'
                    // })
                    // console.log(blob)
                    // let fileName = Date.parse(new Date()) + '.xlsx'
                    // if (window.navigator.msSaveOrOpenBlob) {
                    // // console.log(2)
                    // navigator.msSaveBlob(blob, fileName)
                    // } else {
                    // // console.log(3)
                    // var link = document.createElement('a')
                    // link.href = window.URL.createObjectURL(blob)
                    // link.download = fileName
                    // link.click()
                    // //释放内存
                    // window.URL.revokeObjectURL(link.href)
                    // }
                }).finally(()=>{
                    this.$store.commit('set_loading',{
                        state:false,
                    });
                });
            }else{
                this.$notify({
                    title: '请选择文件！',
                    position: 'bottom-right'
                });
            }
        },
    },
}
</script>
<style lang="scss" scoped>
.download_bt{
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    line-height: 100%;
    cursor: pointer;
    padding: 0 10px;
    box-sizing: border-box;
    >div{
        display: flex;
        justify-content: center;
        align-items: center;
    }
    i{
        width: 24px;
        height: 24px;
        margin-right: 5px;
    }
}
</style>